package com.springboot.mybatis.service.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author sunyt31481
 * @date 2020/8/13 10:07
 * @description
 */
public class ProduceDirectDemo {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connect = RabbitMqUtil.getConnect();
        Channel channel = connect.createChannel();
        String exchangeName = "logs_direct";
        channel.exchangeDeclare(exchangeName, "direct");

        String rootingKey1 = "error";
        String rootingKey2 = "info";
        String rootingKey3 = "warning";

        channel.basicPublish(exchangeName, rootingKey1, null, ("the rootingKey is "+rootingKey1).getBytes());
        channel.basicPublish(exchangeName, rootingKey2, null, ("the rootingKey is "+rootingKey2).getBytes());
        channel.basicPublish(exchangeName, rootingKey3, null, ("the rootingKey is "+rootingKey3).getBytes());

        RabbitMqUtil.closeConnect(channel, connect);
    }
}
